package Veterinaria.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Veterinaria.excepcion.DAOExcepcion;
import Veterinaria.modelo.Factura;
import Veterinaria.negocio.GestionFactura;

/**
 * Servlet implementation class GeneraCodigoFacturaServlet
 */
@WebServlet("/GeneraCodigoFacturaServlet")
public class GeneraCodigoFacturaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GeneraCodigoFacturaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		GestionFactura factura = new GestionFactura();
		System.out.println("Estoy aqui1");
		Factura codigo1 = null;
		try {
			System.out.println("Estoy aqui");
			codigo1 = factura.GenerarCodigoFactura();
			request.setAttribute("codigos", codigo1.getCod_factura());
			System.out.println(codigo1.getCod_factura());


			request.getSession().setAttribute("codigos", codigo1.getCod_factura());
			
			request.getSession().setAttribute("var6", codigo1.getCod_factura());
			response.sendRedirect("factura.jsp");

			
			//RequestDispatcher rd = request
					
			//		.getRequestDispatcher("factura.jsp?id=codigo1.getCod_factura()");
			//rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

}
